/**
 * @file Define all WeChat relevant handlers 
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */

const WebBaseController = require('./web-base-controller');
const SystemServices    = require('../../constants').SystemServices;

/**
 * The WeChatController
 * 
 * @class WeChatController
 * @extends {BaseController}
 */
class WeChatController extends WebBaseController {

    get wechatMessageService() {
        if (!this._wechatMessageService) {
            this._wechatMessageService = this.getSystemService(SystemServices.WECHAT_MESSAGE_SERVICE);
        }
        return this._wechatMessageService;
    }

    get wechatService() {
        if (!this._wechatService) {
            this._wechatService = this.getSystemService(SystemServices.WECHAT_SERVICE);
        }
        return this._wechatService;
    }

    get name() {
        return 'WeChatController';
    }

    get handlersPath() {
        return 'wechat';
    }

    handleWeChatAuthenticationEvent(params, data, parentCallback) {
        this.wechatMessageService.handleWeChatAuthenticationEvent(params, data, (result) => {
            parentCallback(result);
        });
    }

    handleWeChatPlatformAuthorization(params, userId, parentCallback) {
        this.wechatService.handleWeChatPlatformAuthorization(params, userId, (result) => {
            parentCallback(result);
        });
    }

    getPlatformOAuthURL(redirectUri, parentCallback) {
        this.wechatService.getPlatformOAuthURL(redirectUri, (url) => {
            parentCallback(url);
        });
    }

    handleWeChatUserMessage(params, data, parentCallback) {
        this.wechatMessageService.handleWeChatUserMessage(params, data, (data) => {
            parentCallback(data);
        });
    }

    handleWeChatUserAuthorization(authCode, wallId, wallUserId, parentCallback) {
        this.wechatService.handleWeChatUserAuthorization(authCode, wallId, wallUserId, (result) => {
            parentCallback(result);
        });
    }
}

exports.WeChatController = WeChatController;